import io
import json
import os

import numpy as np
import pandas as pd
from openai import OpenAI
if __name__ == '__main__':
    def chen_ming_algorithm(data):
        """
        陈明算法函数，该函数定义了一种特殊的数据集计算过程
        :param data：必要参数，表示带入计算的数据表，用字符串进行表示
        :return：陈明函数计算后的结果，返回结果为表示为JSON格式的Dataframe类型对象
        """
        data = io.StringIO(data)
        df_new = pd.read_csv(data,sep = '\s+',index_col = 0)
        res = np.sum(df_new,axis = 1)-1
        return json.dumps(res.to_string())

    dataFrame = pd.DataFrame({'x1': [1, 2], 'x2': [3, 4]})
    print(chen_ming_algorithm(dataFrame.to_string()))


    functions = {chen_ming_algorithm.__name__: chen_ming_algorithm}
    available_functions = {"chen_ming_algorithm":chen_ming_algorithm}
    chen_ming_algorithm = [
        {
            "function": "chen_ming_algorithm",
            "description": "陈明算法函数，该函数定义了一种特殊的数据集计算过程" ,
            "parameters": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "string",
                        "description": "表示带入计算的数据表，用字符串进行表示"
                    }
                },
                "required": ["data"]
            }
        }
    ]